<?php


namespace app\official\controller;


use app\common\controller\Official;
use think\Exception;
use app\official\model\Region as RegionModel;

class Region extends Official {

    /**
     * 省市区联动
     * @return false|string
     */
    public function childRegion() {
        try {
            $params = $this->checkParams('id');
            if ($params === false) return $this->resErr();
            $list = RegionModel::getDatas([['pid', '=', $params['id']]], 'name,id,city_code');//市或者区
            return $this->resData('success', $list);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 城市列表
     * @return false|string
     */
    public function cityList() {
        try {
            $params = $this->checkParams('');
            if ($params === false) return $this->resErr();
            $list = RegionModel::cityList();
            return $this->resData('success', $list);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

}